/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cxhd.pacs.tools;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import org.dom4j.io.SAXReader;

/**
 *
 * @author Administrator
 */
public class LisXml {

//    static String xml = "<?xml version=\"1.0\" encoding=\"gb2312\" standalone=\"no\"?>\n"
//            + "\n"
//            + "<dw_interface_send_detail><dw_interface_send_detail_row><item_code>WBC</item_code><item_name>白细胞总数</item_name><test_value>10.00</test_value><flag_yq>手工</flag_yq><text_range></text_range><text_danwei>10^6/L</text_danwei><text_note></text_note><sample_no>KK0001</sample_no><date_test>2016-03-23 00:00:00</date_test></dw_interface_send_detail_row><dw_interface_send_detail_row><item_code>RBC</item_code><item_name>红细胞</item_name><test_value>10</test_value><flag_yq>手工</flag_yq><text_range>0-9</text_range><text_danwei>10^9/L</text_danwei><text_note>↑</text_note><sample_no>KK0001</sample_no><date_test>2016-03-23 00:00:00</date_test></dw_interface_send_detail_row><dw_interface_send_detail_row><item_code>HGB</item_code><item_name>血红蛋白</item_name><test_value>115.0</test_value><flag_yq>手工</flag_yq><text_range>120-160</text_range><text_danwei>g/L</text_danwei><text_note>↓</text_note><sample_no>KK0001</sample_no><date_test>2016-03-23 00:00:00</date_test></dw_interface_send_detail_row></dw_interface_send_detail>";

    public static Map<String, String> parsePatientXml(String xml) {
        Map<String, String> map = new HashMap<String, String>();
        try {
            // SAXReader reader = new SAXReader();
            // 通过read方法读取一个文件 转换成Document对象
            Document document = DocumentHelper.parseText(xml);
            //获取根节点元素对象
            Element node = document.getRootElement();

            Element dw_interface_send_info_row = node.element("dw_interface_send_info_row");
            Iterator<Element> it = dw_interface_send_info_row.elementIterator();
            // 遍历

            while (it.hasNext()) {
                // 获取某个子节点对象
                Element e = it.next();

                map.put(e.getName(), e.getText());
            }

        } catch (DocumentException ex) {
            ex.printStackTrace();
        }
        return map;

    }

    public static List<Map<String, String>> parseResultXml(String xml) {
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        try {
            // SAXReader reader = new SAXReader();
            // 通过read方法读取一个文件 转换成Document对象
            Document document = DocumentHelper.parseText(xml);
            //获取根节点元素对象
            Element node = document.getRootElement();

            Iterator<Element> it = node.elementIterator();
            // 遍历

            while (it.hasNext()) {
                // 获取某个子节点对象
                Element e = it.next();
                Map<String, String> map = new HashMap<String, String>();
                Iterator<Element> detail = e.elementIterator();
                while (detail.hasNext()) {
                    Element item = detail.next();
                    map.put(item.getName(), item.getText());
                    
                }
               // System.out.println(map);
                list.add(map);

            }

        } catch (DocumentException ex) {
            ex.printStackTrace();
        }
        return list;

    }
    public static void main(String[] args) {
      String str="KK123132";
      System.out.println(str.substring(0,2));
    }

}
